package pers.qianyu.month_202101.date_20210110;

/**
 * 476. 数字的补数
 * https://leetcode-cn.com/problems/number-complement/
 *
 * @author mizzle rain
 * @date 2021-01-10 11:47
 */
public class FindComplement {
    public int findComplement(int num) {
        int res = 0, a = 0;
        while (num > 0) {
            res += ((num & 1) == 1 ? 0 : 1) << a;
            a++;
            num >>= 1;
        }
        return res;
    }
}
